package enumDemo;

public enum TestEnum {
    //枚举对象
    RED("RED",1),
    WHITE("WHITE",2),
    GREEN("GREEN",3);
    //我们枚举类中的构造方法默认是私有的
   public  String color;
   public   int ordinal;
    TestEnum(String color,int ordinal){
        this.ordinal = ordinal;
        this.color = color;
    }
    public static void main2(String[] args) {
        //从Enum类来的
        //JAVA中的枚举类非常特殊 都是默认继承与java的Enum类
        TestEnum[] testEnums = TestEnum.values();
        for (int i = 0; i < testEnums.length; i++) {
            System.out.println(testEnums[i]+" "+testEnums[i].ordinal());
        }
        //枚举实例化一个对象
        TestEnum testEnum = TestEnum.valueOf("RED");
        System.out.println(testEnum);
        System.out.println(RED.compareTo(WHITE));//返回序号的差值
    }
    public static void main1(String[] args) {
        TestEnum testEnum = TestEnum.RED;
        switch (testEnum) {
            case RED:
                System.out.println("红色");
                break;
            case GREEN:
                System.out.println("绿色");
                break;
            case WHITE:
                System.out.println("白色");
                break;
        }
    }
}